home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / util / cdity / IFX.lha / IFX / AmigaE / input / inputhandler.e next >
Text File  |  1998-01-02  |  3KB  |  145 lines

  1. ->
  2. -> inputhandler.e
  3. ->
  4. -> An object to simplify adding Input Handlers using the
  5. -> input.device.
  6. -> 
  7. OPT MODULE
  8.  
  9. MODULE     'exec/ports',        'exec/io',               'exec/interrupts',
  10.         'exec/lists',        'exec/nodes'    
  11. MODULE     'devices/input'
  12. MODULE     'other/ecodex'
  13.   
  14. ->
  15. -> inputhandler
  16. ->
  17. -> The object maintains its own device pointers, so each
  18. -> new object opens the device again.  This should not be
  19. -> a problem.
  20. ->
  21.  
  22. EXPORT OBJECT inputhandler
  23.     io        :PTR TO iostd
  24.     mp        :PTR TO mp
  25.     is        :PTR TO is
  26.     entry    :LONG
  27.     data    :LONG
  28.     flags    :INT
  29. ENDOBJECT
  30.  
  31. ->       <-
  32. -> FLAGS <-
  33. ->       <-
  34.  
  35. SET IHO_INSTALLED,            -> The handler is currently installed
  36.     IHO_INITIALIZED,        -> The handler has valid fields
  37.     IHO_DUMMY
  38.  
  39. ->         <-
  40. -> METHODS <-
  41. ->         <-
  42.  
  43. ->
  44. -> init()
  45. ->
  46. -> This opens the device and sets up the interrupt server.
  47. -> If the handler was currently installed, this will uninstall
  48. -> it.
  49. ->
  50.  
  51. PROC init(entry, data, pri, name) OF inputhandler HANDLE
  52.     -> If we're already intialized, there's no need
  53.     -> to re-open the device
  54.     IF (self.flags AND IHO_INITIALIZED)=NIL
  55.         -> Message Port
  56.         self.mp := CreateMsgPort()
  57.         IF self.mp=NIL THEN Throw("MP", "INIT")
  58.         
  59.         -> IO Request
  60.         self.io := CreateIORequest(self.mp, SIZEOF iostd)
  61.         IF self.io=NIL THEN Throw("IO", "INIT")
  62.         
  63.         -> Open the device
  64.         IF OpenDevice('input.device', 0, self.io, 0) THEN Throw("DEV", "OPEN")
  65.     
  66.     ENDIF
  67.     
  68.     -> If the handler is currently installed, we should remove it now
  69.     IF (self.flags AND IHO_INSTALLED)<>NIL THEN self.remove()
  70.     
  71.     -> Interrupt server
  72.     IF self.is=NIL THEN NEW self.is
  73.     self.is.code := eCodeInputHandler(entry)
  74.     self.is.data := data
  75.     self.is.ln.pri  := pri
  76.     self.is.ln.name := name
  77.  
  78.     -> Save parameters
  79.     self.entry     := entry
  80.     self.data    := data
  81.     
  82.     -> Set flags
  83.     self.flags := IHO_INITIALIZED
  84. EXCEPT
  85.     IF exception="NEW" THEN ReThrow()
  86.     RETURN exception                    -> Some error happened
  87. ENDPROC NIL
  88.  
  89. ->
  90. -> install()
  91. ->
  92. -> This installs the input handler, using the previously defined
  93. -> stuff.
  94. ->
  95.  
  96. PROC install() OF inputhandler
  97.     IF (self.flags AND IHO_INSTALLED)=NIL AND 
  98.                    (self.flags AND IHO_INITIALIZED)<>NIL
  99.         self.io.command := IND_ADDHANDLER
  100.         self.io.data    := self.is
  101.         DoIO(self.io)
  102.         
  103.         -> Set flags
  104.         self.flags := self.flags OR IHO_INSTALLED
  105.     ENDIF
  106. ENDPROC
  107.  
  108. ->
  109. -> remove()
  110. ->
  111. -> This uninstalls the input handler that was previously
  112. -> installed.
  113. ->
  114.  
  115. PROC remove() OF inputhandler
  116.     IF (self.flags AND IHO_INSTALLED)<>NIL AND
  117.                 (self.flags AND IHO_INITIALIZED)<>NIL
  118.         self.io.command := IND_REMHANDLER
  119.         self.io.data    := self.is
  120.         DoIO(self.io)
  121.         
  122.         -> Set flags
  123.         self.flags := self.flags AND Not(IHO_INSTALLED)
  124.     ENDIF
  125. ENDPROC
  126.  
  127. ->
  128. -> end()
  129. ->
  130. -> This removes the handler, closes the device, and
  131. -> de-allocates the interrupt server structure.
  132. ->
  133.  
  134. PROC end() OF inputhandler
  135.     IF (self.flags AND IHO_INITIALIZED)<>NIL
  136.         IF (self.flags AND IHO_INSTALLED) THEN self.remove()
  137.         CloseDevice(self.io)
  138.         DeleteIORequest(self.io)
  139.         DeleteMsgPort(self.mp)
  140.         END self.is
  141.         
  142.         -> Set flags
  143.         self.flags := self.flags AND Not(IHO_INITIALIZED)
  144.     ENDIF
  145. ENDPROC